# 列表的定义
list_01 = []
number = [1,2,3]
animal = ["elephant","monkey"]
list_02 = [1,2,3,"apple",["111",2],()]
print(list_02)
list_02[1] = "num"
print(list_02)

# 列表遍历
# while循环
i = 0
while i < len(list_02):
    print(list_02[i])
    i += 1
# for循环
for item in list_02:
    print(item)

# 列表添加
# append
print(list_01)
list_01.append(1)
list_01.append(2)
print(list_01)
list_01.extend(animal)
print(list_01)
list_01.insert(1,"num")
print(list_01)

# 删除
print(list_02)
del list_02[1]
print(list_02)
del list_02[1:4]
print(list_02)
item = list_02.pop(1)
print(item)
print(list_02)
list_02.remove('apple')
print(list_02)
list_02.append(2)
list_02.append(2)
print(list_02)
list_02.remove(2)
print(list_02)

# 分片赋值
num = [1,2,3,4,5,6,7]
print(num)
num[4:5] = [9,8,7,6]
print(num)
num[4:] = [9,8,7,6]
print(num)
num[4:4] = [10,5,5,5,5,10]
print(num)
num[4:] = []
print(num)

list_03 = [98,45,13,2,74,68,15,987,0.2]
print(list_03)
list_03.reverse()
print(list_03)
list_03.sort()
print(list_03)
list_03.sort(reverse=True)
print(list_03)
print(list_03)
list_04 = sorted(list_03)
print(list_04)
list_05 = sorted(list_03,reverse=True)
print(list_05)
